﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.ComponentModel;
using System.Collections.Generic;

namespace WP7Client.Helpers
{
    public static class NavigationHelper
    {
        public static Boolean CanShutdown = false;
        public static List<String> PreviousPages = new List<String>();

        /// <summary>
        /// Navigeert naar pagina aan de hand van meegeleverde pad.
        /// </summary>
        /// <param name="path">Pad</param>
        public static void NavigateTo(String path)
        {
            System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => {
                var root = App.Current.RootVisual as PhoneApplicationFrame;

                Uri newUri = new Uri(path, UriKind.Relative);

                if (!root.CurrentSource.Equals(newUri))
                {
                    root.Navigate(newUri);
                    PreviousPages.Add(newUri.OriginalString);
                }
            });
        }

        /// <summary>
        /// Retouneerd het pad van de vorige pagina (indien beschikbaar).
        /// </summary>
        /// <returns>Pad van de vorige pagina(indien beschikbaar)</returns>
        public static String PreviousPage()
        {
            if (PreviousPages.Count > 1)
                return PreviousPages[PreviousPages.Count - 2];
            else
                return "";
        }

        /// <summary>
        /// Verwijderd de laatste naar genavigeerde pagina (indien beschikbaar)
        /// </summary>
        public static void PageBack()
        {
            if (PreviousPages.Count > 1)
                PreviousPages.RemoveAt(PreviousPages.Count - 2);
        }
    }
}
